"""
字典的使用方法介绍
"""
# 字典的定义
user_rich = {}  # 人生财富
mobile_lst = []  # 手机
house_lst = []  # 房子

# 往字典中增加元素
user_rich["mobile"] = mobile_lst
user_rich["house"] = house_lst

# 定义手机对象
mobile_iphone = {"brand": "Apple", "model": "iphone xs max", "memory": "256G", "color": "black"}
mobile_honor = {"brand": "华为", "model": "honor x8", "memory": "256G", "color": "white"}
mobile_xiaomi = dict(brand="小米", model="小米8")
mobile_lst.append(mobile_iphone)
mobile_lst.append(mobile_honor)
mobile_lst.append(mobile_xiaomi)

for mobile in mobile_lst:
    print(mobile["brand"])

# 定义房子对象
house_sz = {"city": "深圳", "year": "2018", "area": "80", "style": "两室一厅", "style": "新房"}
house_bj = {"city": "北京", "year": "2016", "area": "180", "style": "五室一厅"}
house_sz["total_price"] = "600w"
house_bj["total_price"] = "1000w"
house_lst.append(house_sz)
house_lst.append(house_bj)

# 该用户拥有的手机牌子有哪些
for mobile in user_rich["mobile"]:
    print(mobile["brand"])

# 用户的所有财富有哪几种
message = "该用户拥有{}{}个"
for type in user_rich.keys():
    if type == "mobile":
        message = message.format("手机", len(user_rich[type]))
    elif type == "house":
        message = message.format("房子", len(user_rich[type]))
    else:
        message = message.format("现金", len(user_rich[type]))
    print(message)

# 删除字典的元素
user_rich["coin"] = 1000000  # 炒币去了
# 1年后，现金没了，房子没了
del user_rich["coin"]
del user_rich["house"]

# print(user_rich)
